<!--
 * @Author: 赵成刚-车辆详情
-->
<template>
  <view class="vehiclemanagementdetail-box">
    <view
      v-for="(item, index) in formItemList"
      :key="index">
      <view class="u-flex u-row-between vehiclemanagementdetail-item-box">
        <view>{{ item.name }}:</view>
        <view v-if="!item.type">{{ item.value }}</view>
        <view v-else
          ><image
            class="img-box"
            :src="item.value"
            alt=""
            @click="previewImageF(item.value)"
        /></view>
      </view>
    </view>
  </view>
</template>
<script>
import httpEnum from './../../common/httpEnum.js'
export default {
  name: 'vehiclemanagementdetail',
  data() {
    return {
      id: undefined,
      formItemList: [
        // {
        //   name: '车主姓名',
        //   key: 'carOwnerName',
        //   value: '',
        // },
        // {
        //   name: '车主电话',
        //   key: 'carOwnerMobile',
        //   value: '',
        // },
        {
          name: '车头车牌号',
          key: 'carNo',
          value: ''
        },
        {
          name: '挂车车牌号',
          key: 'attachNo',
          value: ''
        },
        // {
        //   name: '车型',
        //   key: 'carType',
        //   value: '',
        // },
        {
          name: '排放标准',
          key: 'emissionValue',
          value: ''
        },
        // {
        //   name: '燃料类型',
        //   key: 'fuelType',
        //   value: '',
        // },
        // {
        //   name: '车货总重',
        //   key: 'carWeight',
        //   value: '',
        // },
        // {
        //   name: '轴数',
        //   key: 'axlNum',
        //   value: '',
        // },
        {
          name: '车头行驶证',
          key: 'headLicense',
          type: 'img',
          value: ''
        },
        {
          name: '挂车行驶证',
          key: 'attachLicense',
          type: 'img',
          value: ''
        },
        {
          name: '车头运输证',
          key: 'headTrans',
          type: 'img',
          value: ''
        },
        {
          name: '挂车运输证',
          key: 'attachTrans',
          type: 'img',
          value: ''
        },
        {
          name: '环保清单',
          key: 'eProtectionSheet',
          type: 'img',
          value: ''
        },
        {
          name: '车辆照片',
          key: 'carPhoto',
          type: 'img',
          value: ''
        }
      ]
    }
  },
  onLoad(options) {
    this.id = options.id
  },
  onShow() {
    this.getDataList()
  },
  methods: {
    //图片预览大图
    previewImageF(val) {
      uni.previewImage({
        current: val, // 当前显示图片的 http 链接
        urls: [val] // 需要预览的图片 http 链接列表
      })
    },
    //根据登录用户查询货源单
    async getDataList() {
      const params = {
        id: this.id
      }
      const { code, result, message } = await this.$u.get(
        '/freight-business/driver/car/info',
        params
      )
      if (code === '0') {
        this.formItemList.forEach((item) => {
          for (const key in result) {
            if (Object.prototype.hasOwnProperty.call(result, key)) {
              if (item.key === key && result[key]) {
                item.value = result[key]
                if (item.type == 'img') {
                  item.value = httpEnum.baseImgUrl + '/app/' + result[key]
                }
              }
            }
          }
        })
      } else {
        this.$api.msg(message)
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.vehiclemanagementdetail-box {
  width: 100%;
  padding: 16rpx 30rpx;
  .vehiclemanagementdetail-item-box {
    border-bottom: 1px solid #f2f2f2;
    line-height: 80rpx;
    display: flex;
    justify-content: space-between;
    .img-box {
      width: 200rpx;
      height: 200rpx;
    }
  }
}
</style>
